$(function () {
    //------------------------------------------------------------------------------------------------------------------
    //企业会员手机号码验证
    $.validator.addMethod("checkMobile", function(value, element,param) {
        var phone =  $("#"+param[0]).val() + '-' + $("#"+param[1]).val() + '-' +$("#"+param[2]).val();
        phone =str_trim(phone);
        if( value == '' && phone == ''  ){
            return false;
        }else {
            return true;
        }
    }, "请输入正确的手机号码");

    //企业会员电话号码验证
    $.validator.addMethod("checkPhone", function(value, element,param) {
        var phone =  $("#"+param[0]).val() + '-' + value + '-' +$("#"+param[1]).val();
        phone =str_trim(phone);
        if(phone != ''){
            var regu =/(^[0-9]{2,5}\-[0-9]{7,9})((\-\d{0,10})?)$/g;
            if(regu.test(phone)){
                return true;
            }else{
                return false;
            }
        }else {
            return true;
        }
    }, "请输入正确的区号和电话号码");

    //企业会员表单验证 使用jQuery Validate 插件进行验证
    $('#partTimeCreateForm').validate({
        //指定使用什么标签标记错误。
        errorElement: "span",
        //一个函数，可以自定义错误放到哪里。
        errorPlacement: function (error, element) {
            $(element).siblings(".errinfo").append(error);
        },
        //自定义错误消息
        tipPlacement: function (element, tip) {
            $(element).siblings(".errinfo").append(tip);
        },
        //通过验证后执行的函数
        success: function (label) {
            if (label.siblings('.errinfo').val() != '') {
                label.text('ok!').addClass('success');
            }
        },
        //未验证后执行的函数
        highlight: function (element, errorClass) {
            $(element).siblings(".errinfo").find('span').removeClass('success');
        },
        ignore: "",
        //js上面添加验证规则
        rules: {
            title: {
                required: true
            },
            type_id: {
                required: true
            },
            need_num: {
                required: true
            },
            sex: {
                required: true
            },
            education: {
                required: true
            },
            salary_price: {
                required: true
            },
            salary_unit: {
                required: true
            },
            salary_method: {
                required: true
            },
            city_id: {
                required: true
            },
            address: {
                required: true
            },
            content: {
                required: true
            },
            contacts: {
                required: true
            },
            mobile: {
                checkMobile:['area_code','phone','ext'] //期望的是true,如果为false则展示提示信息
            },
            phone:{
                checkPhone:['area_code','ext']          //期望的是true,如果为false则展示提示信息
            }
        },
        //错误信息提示修改
        messages: {
            title: {
                required: '兼职名称不能为空'
            },
            type_id: {
                required: '请选择兼职类型'
            },
            need_num: {
                required: '请填写招聘人数'
            },
            sex: {
                required: '请选择性别要求'
            },
            education: {
                required: '请选择学历要求'
            },
            salary_price: {
                required: '请填写薪资价格'
            },
            salary_unit: {
                required: '请选择薪资单位'
            },
            salary_method: {
                required: '请选择薪资结算类型'
            },
            city_id: {
                required: '请选择工作区域'
            },
            address: {
                required: '请填写详细地址'
            },
            content: {
                required: '请填写兼职内容'
            },
            contacts: {
                required: '请填写兼联系人'
            }
        },
        submitHandler: function (form) {
            form.submit();
        }
    });
});

// ----------------------------------------------------------------------------------------------------------------------------

